//
//  WMMusicApiQQ.m
//  WholeMusic
//
//  Created by quanxiong on 2018/2/23.
//  Copyright © 2018年 quanxiong. All rights reserved.
//

#import "WMMusicApiQQ.h"
#import "WMMusicRequestQQ.h"
#import "WMMusicResponseQQ.h"
#import <YYKit/YYKit.h>

@interface WMMusicApiQQ ()

@property (strong, nonatomic) WMMusicRequestQQ *musicRequest;

@end


@implementation WMMusicApiQQ

- (WMMusicRequestQQ *)musicRequest {
    if (!_musicRequest) {
        _musicRequest = [[WMMusicRequestQQ alloc] init];
    }
    return _musicRequest;
}

/**
 * 使用关键词查询歌曲
 */
- (void)searchMusicAsync:(NSString *)keyword page:(int)page complete:(void(^)(NSArray *musicList))complete {
    [self.musicRequest searchMusicWithKeyaord:keyword complete:^(NSDictionary *response) {
        if (complete) {
            WMMusicResponseQQ *resObj = [WMMusicResponseQQ modelWithJSON:response[@"data"][@"song"]];
            [resObj.musicList setValue:@"qq" forKey:NSStringFromSelector(@selector(type))];
            complete(resObj.musicList);
        }
    }];
}

/**
 * 获取某音乐id对应的音乐信息
 */
- (void)getMusicInfoById:(NSString *)musicId complete:(void(^)(id musicInfo))complete {
    assert(false); //未实现
}

/**
 * 获取某音乐id对应的音乐链接
 */
- (void)getMusicLinkByMusic:(WMMusic *)music complete:(void(^)(NSString *musicUrl))complete {
    [self.musicRequest getVKeyWithComplete:^(NSDictionary *response) {
        if (complete) {
            WMMusicResponseVKeyQQ *vkey = [WMMusicResponseVKeyQQ modelWithJSON:response];
            NSString *musicUrl = [vkey musicLink:music];
            if (complete) {
                complete(musicUrl);
            }
        }
    }];
}

/**
 * 获取音乐id列表对应的音乐链接集合
 */
- (void)getMusicLinksByMusics:(NSArray<WMMusic *> *)musics complete:(void(^)(NSArray<NSString *> *musicUrls))complete {
    [self.musicRequest getVKeyWithComplete:^(id response) {
        if (complete) {
        }
    }];
}

/**
 * 获取专辑id对应的专辑信息
 */
- (void)getAlbumInfoById:(NSString *)albumId complete:(void(^)(id musicAlbum))complete {
    
}

@end
